import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: ws
 * Date: 2022-12-21
 * Time: 11:26
 */

// https://www.lanqiao.cn/problems/595/learning/?contest_id=74
public class Test {
    //该题转换成一张网

    //设置各个结点的子节点
    static Map<Character, char[]> mp = new HashMap<>();
    static {
        mp.put('a', new char[]{'f', 'b'});
        mp.put('b', new char[]{'a', 'g', 'c'});
        mp.put('c', new char[]{'b', 'g', 'd'});
        mp.put('d', new char[]{'e', 'c'});
        mp.put('e', new char[]{'f', 'g', 'd'});
        mp.put('f', new char[]{'a', 'g', 'e'});
        mp.put('g', new char[]{'f', 'b', 'c', 'e'});
    }
    //将不同长度的链表存入st中
    static Set<Set<Character>> st = new HashSet<>();
    //深度优先遍历，将不同深度的子链长添加到st
    static void dfs(Set<Character> curr, char c) {
        //将初始链表加入，后面该链表的长度会递增（就会变成另一个字迹），直到达到阈值
        st.add(curr);
        //达到规定的最长值
        if (curr.size() == 7) return;
        //Map<k, v>, vde值为一个char[]
        char[] get = mp.get(c);
        for (int i = 0; i < get.length; i++) {
            //获得c的字节点元素，将其加到curr后，长度加1
            char ch = get[i];
            if (curr.contains(ch)) continue;
            Set<Character> newCurr = new HashSet<>(curr);
            newCurr.add(ch);
            //递归，直到当前Curr.size()为7
            dfs(newCurr, ch);
        }
    }

    public static void main(String[] args) {
        for (char c = 'a'; c <= 'g'; ++c) {
            //将从不同的首节点开始
            HashSet<Character> curr = new HashSet<>();
            curr.add(c);
            dfs(curr, c);
        }
        System.out.println(st.size());
    }
}
